package ru.nnstu.medialib.dao;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.Transaction;

import ru.nnstu.medialib.domain.Photo;
import ru.nnstu.medialib.domain.PhotoAlbum;

public class PhotoAlbumDAOImpl implements PhotoAlbumDAO {

	@Override
	public void savePhotoAlbum(PhotoAlbum photoAlbum) {
		Session session = HibernateUtil.getSession();
		Transaction tr = session.beginTransaction();
		session.save(photoAlbum);
		tr.commit();		
	}

	@Override
	public List<PhotoAlbum> listPhotoAlbum() {
		Session session = HibernateUtil.getSession();
		Criteria crit = session.createCriteria(PhotoAlbum.class);
		return crit.list();
	}

	@Override
	public void removePhotoAlbum(Long id) {
		Session session = HibernateUtil.getSession();
		Object obj = session.load(PhotoAlbum.class, id);
		session.delete(obj);		
	}

}
